package com.mark.media.service.impl;

import com.mark.common.media.constans.WmMediaConstans;
import com.mark.media.service.StatisticsService;
import com.mark.model.common.dtos.ResponseResult;
import com.mark.model.common.enums.AppHttpCodeEnum;
import com.mark.model.mappers.wemedia.WmNewsStatisticsMapper;
import com.mark.model.mappers.wemedia.WmUserMapper;
import com.mark.model.media.dtos.StatisticDto;
import com.mark.model.media.pojos.WmNewsStatistics;
import com.mark.model.media.pojos.WmUser;
import com.mark.utils.common.BurstUtils;
import com.mark.utils.threadlocal.WmThreadLocalUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description :  Love Story
 * @Author :  Markburt
 * @CreateDate :  2020/3/8$ 下午 03:09$
 * @UpdateUser :  Markburt
 * @UpdateDate :  2020/3/8$ 下午 03:09$
 * @UpdateRemark :  Project Build
 * @Version :  1.0
 */
@Service
@SuppressWarnings("all")
public class StatisticsServiceImpl implements StatisticsService{

    @Autowired
    WmUserMapper wmUserMapper;

    @Autowired
    WmNewsStatisticsMapper wmNewsStatisticsMapper;



    /***
     * 查找图文统计数据
     * @param dto
     * @return
     */
    @Override
    public ResponseResult findWmNewsStatistics(StatisticDto dto) {
        if(dto==null && dto.getType()==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        if(WmMediaConstans.WM_NEWS_STATISTIC_CUR !=
                dto.getType() && (dto.getStime()==null || dto.getEtime()==null)){

            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //查询用户
        WmUser user = WmThreadLocalUtils.getUser();
        WmUser wmUser = wmUserMapper.selectById(user.getId());
        String burst = BurstUtils.groudOne(wmUser.getApUserId());
        List<WmNewsStatistics> list = wmNewsStatisticsMapper.findByTimeAndUserId(burst, wmUser.getApUserId(), dto);
        return ResponseResult.okResult(list);
    }
}
